import java.util.*;
import java.io.*;

public class Checkpoint07 {

	public static void main(String[] args) throws FileNotFoundException{
		Scanner console = new Scanner(System.in);
		File chosenFile = getInput(console);
		int fileCount = fileCount(chosenFile);
		System.out.print(fileCount + " total numbers found in " + chosenFile);
	}
	
	public static File getInput(Scanner console){
		System.out.print("input file name? ");
		File chosenFile = new File(console.nextLine()); //designates the correct file
		while(!chosenFile.canRead()){ //designates all files not-allowed
			System.out.println("File not found.  Try again.");
			System.out.print("input file name? ");
			chosenFile = new File(console.nextLine());	
		}
		return chosenFile;
	}
	
	public static int fileCount(File chosenFile) throws FileNotFoundException{
		Scanner input = new Scanner(chosenFile);
		int fileCount = 0;
		while (input.hasNext()){
			fileCount++;
			String text = input.next();
			System.out.print(text);
			System.out.println(" -- " +fileCount);
		}
		return fileCount;
	}
	
}